<template>
  <el-card class="box-card">
    <template #header>
      <div class="card-header">
        <span>{{ title }}</span>
        <div class="select" v-if="showSelect">
          <el-select
            v-model="value"
            class="m-2"
            placeholder="Select"
            @change="changeDayLength"
          >
            <el-option
              v-for="item in options"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            >
            </el-option>
          </el-select>
        </div>
      </div>
    </template>
    <div class="item">
      <slot></slot>
    </div>
  </el-card>
</template>

<script lang="ts">
import { defineComponent } from 'vue'
import { ref } from 'vue'
import { useStore } from '@/store'
export default defineComponent({
  components: {},
  props: {
    title: {
      type: String,
      default: 'Title'
    },
    pageName: {
      type: String,
      required: true
    },
    showSelect: {
      type: Boolean,
      default: false
    },
    showFooter: {
      type: Boolean,
      default: true
    }
  },
  setup(props) {
    const store = useStore()
    const value = ref('')
    const options = [
      {
        value: '7',
        label: 'week'
      },
      {
        value: '30',
        label: 'month'
      },
      {
        value: '180',
        label: 'six-month'
      }
    ]
    const changeDayLength = (value: any) => {
      store.dispatch('general/changeDayLengthAction', {
        value: value,
        pageName: props.pageName
      })
    }
    return {
      value,
      options,
      changeDayLength
    }
  }
})
</script>

<style lang="less" scoped>
.box-card {
  &:deep(.el-card__header) {
    padding: 10px 20px !important;
  }
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  height: 30px;
}

.item {
  margin-bottom: 10px;
  // border: 1px solid red;
}
</style>
